<template>
  <el-container class="index">
    <el-header>
      <div class="logo">
        <img src="../assets/QQ图片20191229181353.gif" alt />
      </div>
      <div class="title">
        <h1>老字号电商管理系统</h1>
      </div>
      <div class="logout">
        <el-button type="danger" @click="out">退出</el-button>
      </div>
    </el-header>
    <el-container>
      <!-- 侧边栏 -->
      <el-aside width="200px">
        <el-menu
          router
          unique-opened
          :default-active="defaultActive"
          class="el-menu-vertical-demo"
          background-color="#545c64"
          text-color="#fff"
          active-text-color="#ffd04b"
        >
          <el-submenu :index="menu.path" v-for="menu in menuList" :key="menu.id">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>{{menu.authName}}</span>
            </template>
            <el-menu-item :index="v.path" v-for="v in menu.children" :key="v.id">
              <i class="el-icon-menu"></i>
              <span slot="title">{{v.authName}}</span>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>

      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data () {
    return {
      menuList: []
    }
  },
  computed: {
    defaultActive () {
      return this.$route.path.slice(1).split('-')[0]
    }
  },

  created () {
    this.$axios.get('menus', {
    }).then(res => {
      const data = res.data
      console.log(data)
      if (res.meta.status === 200) {
        this.menuList = data
      } else {
        this.$message.error('哒哒哒')
      }
    })
  },
  methods: {
    out () {
      this.$confirm('你确定要提前下班吗', '乌啦啦', {
        type: 'warning'
      }).then(() => {
        this.$message.success('加班，不然扣奖金')
        localStorage.removeItem('token')
        this.$router.push('/login')
      }).catch(() => {
        this.$message.error('这样才是好孩子')
      })
    }
  }
}
</script>

<style lang="less" scoped>
.index {
  height: 100%;
  .el-header {
    display: flex;
    background-color: pink;
    .logo {
      width: 180px;
      img {
        width: 180px;
        height: 60px;
      }
    }
    .title {
      flex: 1;
      text-align: center;
      line-height: 60px;
    }
    .logout {
      width: 180px;
      line-height: 60px;
      text-align: center;
    }
  }
  .el-aside {
    background-color: skyblue;
  }
  .el-main {
    background-color: #e6e6e6;
  }
}
.el-menu {
  border-right: none;
}
</style>
